const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0].title = '一杆云枢'
        args[0].templateParameters = {
          ...args[0].templateParameters,
          errorHandlerScript: `
            <script>
              (function() {
                const suppressErrors = () => {
                  const originalError = console.error;
                  const originalWarn = console.warn;

                  const isResizeError = (msg) =>
                    typeof msg === 'string' && msg.includes('ResizeObserver');

                  console.error = (...args) => {
                    if (isResizeError(args.join(' '))) return;
                    originalError.apply(console, args);
                  };

                  console.warn = (...args) => {
                    if (isResizeError(args.join(' '))) return;
                    originalWarn.apply(console, args);
                  };

                  window.addEventListener('error', (e) => {
                    if (isResizeError(e.message)) {
                      e.preventDefault();
                      return false;
                    }
                  }, true);
                };

                suppressErrors();
                document.addEventListener('DOMContentLoaded', suppressErrors);
              })();
            </script>
          `
        }
        return args
      })
  },
  configureWebpack: {
    resolve: {
      fallback: {
        "http": false,
        "https": false,
        "util": false,
        "zlib": false,
        "stream": false,
        "url": false,
        "assert": false,
        "crypto": false
      }
    },
    plugins: [
      new (require('webpack')).DefinePlugin({
        __VUE_OPTIONS_API__: JSON.stringify(true),
        __VUE_PROD_DEVTOOLS__: JSON.stringify(false),
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false)
      })
    ]
  },
  devServer: {
    client: {
      overlay: false // 完全禁用错误覆盖层
    },
    proxy: {
      '/api': {
        target: 'http://113.46.199.88:3001',
        changeOrigin: true,
      },
      '/uploads': {
        target: 'http://113.46.199.88:3001',
        changeOrigin: true,
      }
    }
  }
})
